/*
 * Repository.h
 *
 *  Created on: 05/08/2013
 *      Author: marcio
 */

#ifndef REPOSITORY_H_
#define REPOSITORY_H_

template<typename T>
class Repository {
private:
	long long size;
	long long last;
	T** repo;

public:
	Repository(long size, long number);

	virtual ~Repository();

	T* getFrom();

	void release(T* elem);
};

template<typename T>
Repository<T>::Repository(long size, long number){
	repo = new T*[size];
	for(long long i = 0; size; i++){
		repo[i] = T[number];
	}
	this->size = size;
	this->last = size-1;
}

template<typename T>
virtual Repository<T>::~Repository(){
	for(long long i = 0; size; i++){
		delete repo[i];
	}
	delete repo;
}

template<typename T>
T* Repository<T>::getFrom(){
	if(last > 0 ) return repo[last--];
	else return NULL;
}

template<typename T>
void Repository<T>::release(T* elem){
	last++;
	repo[last] = elem;
}

#endif /* REPOSITORY_H_ */
